package myhashset;

import java.util.Objects;

public class Student implements Comparable<Student> {
    private String name;
    private Integer age;

    public Student() {
    }

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student)) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name) && Objects.equals(age, student.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }


    @Override
    public int compareTo(Student o) {
//        return age-o.getAge();
//        if(age.equals(o.getAge()))
//            return 0;
//        return -1;
//        return name.compareTo(o.getName());
//        int result = 0;
//        if (age.equals(o.getAge())) {
//            result = name.compareTo(o.getName());
//        } else {
//            result = age - o.getAge();
//        }
//        return result;

//        int result = 0;
//        if (age.equals(o.getAge())) {
//            return name.compareTo(o.getName());
//        } else {
//            return age - o.getAge();
//        }
//        return result;

        if (this.age.equals(o.getAge())) {
            return name.compareTo(o.getName());
        }
        return age - o.getAge();
    }
}
